<?php
	require_once('registerView.php');
	require_once('registerHandler.php');

	class RegisterController {
		
		/**
		 * @return string $html
		 */
		public function DoControll(LoginHandler $lh, Database $db) {
			$html = "";
			$rw = new RegisterView();
			
			if (!$lh->IsLoggedIn()) {
				$html .= $rw->DoRegisterBox();
			} else {
				$html .= $rw->DoAlreadyRegisterdBox();
			}
			
			if ($rw->TriedToRegister()) {
				$errorCode = $this->Register($rw, $db);
				$html .= $rw->ErrorHandler($errorCode);
			}
			
			return $html;
		}
		
		/**
		 * @return const $errorCode
		 */
		public function Register(RegisterView $rw, Database $db) {
			$rh = new RegisterHandler($db);
			
			return $rh->Register($rw);
		}
	}
?>